package com.zw._05_topic;

import com.rabbitmq.client.*;
import com.zw.ConnectionUtil;

import java.io.IOException;

public class Recv1 {
    public static final String QUEUE_DELETE= "queue_delete";
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_DELETE,true,false, false, null);
        channel.queueBind(QUEUE_DELETE, Send.EXCHANGE_NAME, "user.*");
        channel.basicQos(1);
        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者票据:" + consumerTag);
                System.out.println("DeliveryTag:" + envelope.getDeliveryTag());
                System.out.println("交换机:" + envelope.getExchange());
                System.out.println("队列key:" + envelope.getRoutingKey());
                System.out.println("body:" + new String(body));
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        };
        channel.basicConsume(QUEUE_DELETE, false, consumer);
    }
}
